﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace AgileDashboard.Entities
{
    public enum WorkItemType
    {
        None,
        Bug,
        Task,
        User_Story
    }

    public class WorkItem
    {
        public string AreaPath { get; set; }


        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int Id { get; set; }

        public string Description { get; set; }
        public string IterationPath { get; set; }
        public string Title { get; set; }

        [NotMapped]
        public Uri Uri { get; set; }

        public string State { get; set; }

        public DateTime ChangedDate { get; set; }
        public string ChangedBy { get; set; }


        [NotMapped]
        public int Depth { get; set; }





        public WorkItemType WorkItemType { get; set; }
        public List<WorkItem> LinkedWorkedItems { get; set; }
        
        public string Status { get; set; }
        public int? WinningVote { get; set; }
        public DateTime CreationTimeStamp { get; set; }
        public string CreatedBy { get; set; }
        public DateTime UpdateTimeStamp { get; set; }
        public string UpdatedBy { get; set; }


        [NotMapped]
        public string ShortDescription
        {
            get
            {
                if (DescriptionNeedsTruncating)
                    return Description.Substring(0, 120) + " .... ";
                else
                    return Description;
            }


        }

        public bool DescriptionNeedsTruncating
        {
            get
            {
                if (Description != null && Description.Length > 120)
                {
                    return true;
                }
                else
                {
                    return false;

                }
            }

        }

        [NotMapped]
        public bool CanVote { get; set; }

        [NotMapped]
        public int VoteCount { get; set; }


        public virtual ICollection<VoteDetail> VoteDetails { get; set; }


        

        
    }
}
